package leetcode;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author Liangyaoyun
 */
public class leetCode232 {
    // java中的 Stack 有设计上的缺陷，官方推荐使用 Deque(双端队列) 代替 Stack
    Deque<Integer> inStack;
    Deque<Integer>outStack;
    public leetCode232() {
        //创建两个“栈”，一个入栈，一个出栈
        inStack=new ArrayDeque<>();
        outStack=new ArrayDeque<>();
    }


    public void push(int x) {
        //将元素压进inStack
        inStack.push(x);

    }


    public int pop() {
        //将“入栈”中的所有元素压进“出栈”中
        if (outStack.isEmpty()){
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
        return outStack.pop();

    }

    public int peek() {

        if (outStack.isEmpty()){
            while (!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }

        return outStack.peek();

    }

    public boolean empty() {
        if (outStack.isEmpty()&&inStack.isEmpty()){
            return true;
        }
        else  {
            return  false;
        }
    }
}
